<template>
  <div class="send-detail">
    <el-dialog
      title="&quot; 未推送条目数 &quot; 每小时更新一次"
      :visible.sync="detailVisible"
      custom-class="show-dialog"
      width="50%"
      :before-close="handleCloseDetail"
    >
      <el-button
        type="primary"
        size="mini"
        @click="handleExcuteReminder"
      >
        提醒
      </el-button>
      <el-table
        :data="detailList"
        height="500"
        style="margin-top:10px;"
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          prop="userName"
          label="推送人员"
        />
        <el-table-column
          prop="taskNum"
          label="任务数"
        />
        <el-table-column
          prop="toPushNum"
          label="未推送"
        />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { getSendMessage } from '@/api/coupon/template'
export default {
  props: {
    detailVisible: {
      type: Boolean,
      default: false
    },
    detailList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      multipleSelection: []
    }
  },
  methods: {
    handleCloseDetail() {
      this.$emit('closeReminder')
    },
    handleSelectionChange(val) {
      console.log('val is', val)
      this.multipleSelection = val
    },
    async handleExcuteReminder() {
      const userIds = []
      this.multipleSelection.forEach(user => {
        if (user.toPushNum > 0) {
          userIds.push(user.userId)
        }
      })
      console.log(userIds)
      if (userIds.length === 0) {
        this.$message({
          message: '请选择待提醒店长',
          type: 'info'
        })
        return
      }
      const requestData = {
        userIds
      }
      const sendRes = await getSendMessage(requestData)
      console.log(sendRes)
      if (sendRes.errcode === 0) {
        this.$message({
          message: sendRes.resultMesg,
          type: 'success'
        })
      } else {
        this.$message({
          message: sendRes.resultMesg,
          type: 'info'
        })
      }
      // 关闭弹窗
      this.handleCloseDetail()
    }
  }
}
</script>
